<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <a-button type="danger" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}</a-button>
                        <a-button type="primary" @click="clearLogs">{{i18n('list.clearLogsBtn','清空日志')}}</a-button>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right"  v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="$ti18('rxForm.createTime','创建时间')">
                            <a-range-picker @change="onChange" allowClear></a-range-picker>
                        </a-form-item>
                        <a-form-item :label="i18n('taskLog.logType','日志类型')">
                            <a-select v-model="queryParam.Q_RESULT__S_EQ" :options="resultOptions" />
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    :url="'/api-system/system/core/sysHttpTaskLog/getPageByTaskId?taskId='+taskId"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="logId"
                    @selectChange="onSelectChange"
                >
                    <span slot="result" slot-scope="{ text, record }">
                        <a-tag :color="resultMap[text].color">
                            <span>{{ resultMap[text].text }}</span>
                        </a-tag>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span @click.stop="logDetail(record)">{{i18n('list.viewLogBtn','查看日志')}}</span>
                        <span @click.stop="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
    import SysHttpTaskLogApi from '@/api/system/core/sysHttpTaskLog'
    import {BaseList, RxFit, RxGrid, RxUserInfo, Util} from "@lowcode/jpaas-common-lib";
    import SysHttpTaskLogDetail from "./SysHttpTaskLogDetail";
    export default {
        name: 'SysHttpTaskLogList',
        mixins: [BaseList],
        props:["taskId"],
        components: {
            RxFit,
            RxGrid,
            RxUserInfo
        },
        data() {
            return {
                columns: [
                    {
                        title: this.$ti18('rxList.index','序号'),
                        type: 'indexColumn',
                        width: 100,
                        dataIndex: 'serial',
                        scopedSlots: {customRender: 'serial'}
                    },
                    {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', width: 100},
                    {title: this.i18n('taskLog.logType','日志类型'), dataIndex: 'result', width: 100, scopedSlots: {customRender: 'result'}},
                    {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
                ],
                comment: this.i18n('taskLog.comment','接口调用日志表'),
                widthHeight: ['800px', '600px'],
                fitSearch: false,
                resultMap: {
                    '1': { color: 'green', text: this.i18n('taskLog.successLog','成功日志') },
                    '0': { color: 'red', text: this.i18n('taskLog.failureLog','失败日志') }
                },
                resultOptions: [
                    {label: this.i18n('taskLog.successLog','成功日志'), value: '1'},
                    {label: this.i18n('taskLog.failureLog','失败日志'), value: '0'}
                ],
            }
        },
        methods: {
            i18n(name, text, key) {
                return this.$ti18(name, text, "SysHttpTask", key);
            },
            //fsad
            delById(ids) {
                return SysHttpTaskLogApi.del({ids: ids.join(',')});
            },
            getListByParams(parameter) {
                return SysHttpTaskLogApi.query(parameter)
            },
            search() {
                this.$refs.table.loadData()
            },
            cancel() {
                this.resetSearch();
            },
            close() {
                //关闭按钮
                this.fitSearch = false;
            },
            getTime(time){
                if(time) {
                    return time / 1000 + this.i18n('taskLog.seconds','秒');
                }else{
                    return "0" + this.i18n('taskLog.seconds','秒');
                }
            },
            clearLogs(){
                var self=this;
                SysHttpTaskLogApi.clearAll().then(res=>{
                    self.resetSearch();
                });
            },
            logDetail(record){
                Util.open({
                    component: SysHttpTaskLogDetail,
                    curVm:this,
                    widthHeight:['800px','600px'],
                    title: this.i18n('taskLog.detailTitle','调用日志'),
                    data:{
                        pkId:record.pkId
                    }
                },function () {})
            },
            onChange(date,dateStr){
                this.$set(this.queryParam,"Q_CREATE_TIME__D_GE",dateStr[0]);
                this.$set(this.queryParam,"Q_CREATE_TIME__D_LE",dateStr[1]);
            }
        }
    }
</script>
<style scoped>

</style>

